from pymy3000 import myapi
from .error import *
from .cursor import *
DEFAULT_CHARSET = 'utf8'
class Connection(object):
    """
    self.__mysql_handle should be MYSQL* handle.
"""
    def __init__(self,**kwargs): #host,user,db,port,passwd,charset='utf-8'
        host=kwargs['host']
        port=kwargs.get('port',3306)
        user=kwargs['user']
        passwd=kwargs.get('passwd','')
        db=kwargs['db']
        charset=kwargs.get('charset',DEFAULT_CHARSET)
        try:
            self.__mysql_handle=myapi.connect(host,port,user,passwd,db,charset)
        except BaseException as e:
            raise Error(e)
    def __rowcount(self):
        return myapi.rowcount(self.__mysql_handle)
    def __execute(self,sql,p):
        return myapi.execute(self.__mysql_handle,sql,p)
    def __resultClose(self):
        myapi.resultsetClose(self.__mysql_handle)
    def close(self):
        myapi.close(self.__mysql_handle)
    def commit(self):
        raise NotSupportedError('developing ...')
    def rollback(self):
        raise NotSupportedError('developing ...')
    def cursor(self):
        return Cursor(self)
